package com.hkts.management.unattended.poundroom.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.unattended.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.unattended.poundroom.service.IYbMutualInventoryService;
import com.hkts.management.unattended.poundroom.entity.YbMutualInventory;

import java.util.List;

/**
 * @author zy
 * @since 2021-10-13
 */
@RestController
@RequestMapping("/mutual/ybMutualInventory")
public class YbMutualInventoryController {
    private final Logger logger = LoggerFactory.getLogger(YbMutualInventoryController.class);

    @Autowired
    public IYbMutualInventoryService iYbMutualInventoryService;

    /**
     * 分页查询数据
     *
     * @param page              分页信息
     * @param ybMutualInventory 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getYbMutualInventoryPageList")
    public Result<Object> getHontUserList(Page<YbMutualInventory> page, YbMutualInventory ybMutualInventory) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iYbMutualInventoryService.selectPage(page, ybMutualInventory)));
    }

    /**
     * 保存和修改公用的
     *
     * @param ybMutualInventory 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualInventorySave")
    public Result<Object> ybMutualInventorySave(YbMutualInventory ybMutualInventory) {
        iYbMutualInventoryService.saveOrUpdate(ybMutualInventory);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/ybMutualInventoryGetById")
    public Result<Object> ybMutualInventoryGetById(String id) {
        YbMutualInventory byId = iYbMutualInventoryService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualInventoryDelete")
    public Result<Object> hontUserDelete(String id) {
        iYbMutualInventoryService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualInventoryBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iYbMutualInventoryService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

}
